﻿using Lifang.Common;
using Lifang.Entites;
using System;
using System.Collections.Generic;
using System.Text;

namespace Lifang.Dao
{
    public class ArticleContentDao : BaseDao<DP_ArticleContent>
    {
        public ArticleContentDao() : base()
        {

        }

        public ArticleContentDao(LoginUserModel loginUserModel) : base(loginUserModel)
        {

        }


        #region  新增或保存实体
        public CommonResult SaveOrUpdateMod(DP_ArticleContent mod, SqlNote note=null, List<string> mustUpdateList = null)
        {

            var re = new CommonResult();
            if (mod.Id == 0)
            {
                SetCreateInfo(mod);
                var i = new DapperHelper().InserData(mod, note);
                if (i > 0)
                {
                    return re;
                }
            }
            else
            {
                SetUpdateInfo(mod);
                var old = new DapperHelper().SelectModel<DP_ArticleContent>(mod.Id, note);

                if (mustUpdateList == null)
                {
                    mustUpdateList = new List<string>() { DP_ArticleContentValue.Content, DP_ArticleContentValue.DataFlag, DP_ArticleContentValue.IsDel, DP_ArticleContentValue.ImageUrlOne, DP_ArticleContentValue.ImageUrlTwo, DP_ArticleContentValue.ImageType };
                }

                var i = new DapperHelper().UpdateExecute(mod, note, mustUpdateList);                

            }
            return re;
        }
        #endregion


        #region 设置新增或修改人信息
        public void SetCreateInfo(DP_ArticleContent mod)
        {
            mod.CreateUserNo = OpUser.UserNo;
            mod.CreateUserName = OpUser.UserName;
            mod.CreateDateTime = DateTime.Now;
        }

        public void SetUpdateInfo(DP_ArticleContent mod)
        {
            mod.UpdateUserNo = OpUser.UserNo;
            mod.UpdateUserName = OpUser.UserName;
            mod.UpdateDateTime = DateTime.Now;
        }
        #endregion

    }
}
